import 'package:flutter/material.dart';
import 'package:flutterdemo01/demo1/page/HomePage.dart';
import 'package:flutterdemo01/demo1/page/NewsPage.dart';
import 'package:flutterdemo01/demo1/page/SettingPage.dart';

main() {
  runApp(AppDemo());
}

class AppDemo extends StatefulWidget {
  const AppDemo({Key? key}) : super(key: key);

  @override
  _AppDemoState createState() => _AppDemoState();
}

class _AppDemoState extends State<AppDemo> {
  List _pages = [HomePage(), NewsPage(), SettingPage()];

  int _chooseIndex = 0;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(primaryColor: Colors.lightBlue),
      home: Scaffold(
        appBar: AppBar(
          title: Text('appdemo'),
        ),
        body: _pages[_chooseIndex],
        bottomNavigationBar: BottomNavigationBar(
          currentIndex: _chooseIndex,
          iconSize: 20,
          selectedItemColor: Colors.red,
          items: [
            BottomNavigationBarItem(icon: Icon(Icons.home), label: '首页'),
            BottomNavigationBarItem(icon: Icon(Icons.message), label: '消息'),
            BottomNavigationBarItem(icon: Icon(Icons.settings), label: '设置'),
          ],
          onTap: (index) {
            setState(() {
              _chooseIndex = index;
            });
          },
        ),
      ),
    );
  }
}

// class AppDemo extends StatelessWidget {
//   int _currentPage = 0;
//
//   @override
//   Widget build(BuildContext context) {
//     return MaterialApp(
//       theme: ThemeData(primaryColor: Colors.lightBlue),
//       home: Scaffold(
//         appBar: AppBar(title: Text('appdemo'),),
//         bottomNavigationBar: BottomNavigationBar(
//           currentIndex: _currentPage,
//           items: [
//             BottomNavigationBarItem(icon: Icon(Icons.home), label: '首页'),
//             BottomNavigationBarItem(icon: Icon(Icons.home), label: '新闻'),
//             BottomNavigationBarItem(icon: Icon(Icons.home), label: '设置'),
//           ],
//           onTap: (index) {
//             print('点击的index:$index');
//           },
//         ),
//         body: MyPage(),
//
//       ),
//     );
//   }
// }
//
//
// class MyPage extends StatefulWidget {
//   const MyPage({Key? key}) : super(key: key);
//
//   @override
//   _MyPageState createState() => _MyPageState();
// }
//
// class _MyPageState extends State<MyPage> {
//   @override
//   Widget build(BuildContext context) {
//     return Container(width: 200,height: 200,color: Colors.yellow,);
//   }
// }
